#include <iostream>

using namespace std;

int main(void) {

	int times = 0;
	int status = 0;
	char ch;


	scanf("%d", &times);
	getchar();

	for(int i = 0; i < times; i++)
	{
		ch = getchar();

		while(ch != '\n')
		{
			if (ch == 'P' && status == 0)
			{
				status = 1;
			}
			if (ch == 'A' && status == 1)
			{
				status = 2;
			}
			if (ch == 'T' && status == 2)
			{
				status = 3;
			}
			
			ch = getchar();
		}

		if (status == 3)
		{
			printf("YES\n");
		} else 
		{
			printf("NO\n");
		}

		status = 0;
	}



    
    return 0;
}